package com.ruoyi.web.controller.disasterAssessment;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.disasterassessment.domain.IotWarning;
import com.ruoyi.disasterassessment.service.IIotWarningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 数据测点告警Controller
 * 
 * @author hcc
 * @date 2023-12-21
 */
@RestController
@RequestMapping("/disasterassessment/warning")
public class IotWarningController extends BaseController
{
    @Autowired
    private IIotWarningService iotWarningService;

    /**
     * 查询数据测点告警列表
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:warning:list')")
    @GetMapping("/list")
    public TableDataInfo list(IotWarning iotWarning)
    {
        startPage();
        List<IotWarning> list = iotWarningService.selectIotWarningList(iotWarning);
        return getDataTable(list);
    }

    /**
     * 导出数据测点告警列表
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:warning:export')")
    @Log(title = "数据测点告警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IotWarning iotWarning)
    {
        List<IotWarning> list = iotWarningService.selectIotWarningList(iotWarning);
        ExcelUtil<IotWarning> util = new ExcelUtil<IotWarning>(IotWarning.class);
        util.exportExcel(response, list, "数据测点告警数据");
    }

    /**
     * 获取数据测点告警详细信息
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:warning:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(iotWarningService.selectIotWarningById(id));
    }

    /**
     * 新增数据测点告警
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:warning:add')")
    @Log(title = "数据测点告警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IotWarning iotWarning)
    {
        return toAjax(iotWarningService.insertIotWarning(iotWarning));
    }

    /**
     * 修改数据测点告警
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:warning:edit')")
    @Log(title = "数据测点告警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IotWarning iotWarning)
    {
        return toAjax(iotWarningService.updateIotWarning(iotWarning));
    }

    /**
     * 删除数据测点告警
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:warning:remove')")
    @Log(title = "数据测点告警", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(iotWarningService.deleteIotWarningByIds(ids));
    }
}
